home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Shareware Plus / Developers / Library / NGL 2.0 Demo / NGL2.0.0(E)Demo / Cel & Rotate Sample / Cel & Rotate Sample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-03  |  2.5 KB  |  129 lines

  1. /*============================================================
  2.  
  3.                     Cel & Rotate sample program
  4.                     
  5. ============================================================*/
  6. #include        "N_Library.h"
  7.  
  8. short        Data_Rsrc = 0;
  9. long            total_step = 0;
  10. long            wait;
  11. short        i,r=0;
  12. short        x[128];
  13. short        y[128];
  14. short        rt[128];
  15. short        sp[128];
  16.  
  17. void main(void)
  18. {
  19.     WindowPtr    window;
  20.     short        p,xx,yy;
  21.  
  22.     ToolboxInit();
  23.     ColorCheck();
  24.     HideMenuBar();
  25.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  26.     N_Window_Set(window,-(window->portBits.bounds.left),-(window->portBits.bounds.top),640,480);
  27.      Open_Resource_File(128,1,&Data_Rsrc);
  28.     N_Sp_Make(640,480);                                                //initialize sprite offscreen
  29.     N_Cel_Make2(640,480);                                                //keep cel plane work area
  30.     HideCursor();
  31.     N_Pict_Draw(128,0,0,(GrafPtr)Main_Window,true);
  32.     N_Sprite_Set(130,0,32,32,0,1,1,1);                                    //Sp 0(rotation mode)
  33.     N_Sprite_Set(201,1,32,32,0,1,1,0);                                    //Sp 1
  34.     N_Sprite_Set(202,2,32,32,0,1,1,0);                                    //Sp 2
  35.     Delay(60,&wait);
  36.     Close_Resource_File(&Data_Rsrc);
  37.  
  38.     for (i=0;i!=128;i++)                                                    
  39.     {
  40.         x[i] = GetRandom(0,640-48);
  41.         y[i] = GetRandom(0,480-48);
  42.         sp[i] = GetRandom(2,5)*2;
  43.         rt[i] = 0;
  44.     }
  45.     do
  46.     {
  47.         if (GetRandom(0,1)==0)
  48.         {
  49.             N_Sp_Put(0x80000000+1,GetRandom(0,19)*32,GetRandom(0,14)*32);
  50.         }
  51.         else
  52.         {
  53.             N_Sp_Put(0x80000000+2,GetRandom(0,19)*32,GetRandom(0,14)*32);
  54.         }
  55.     
  56.         if (total_step<128)
  57.         {
  58.             for (i=0;i!=24;i++)
  59.             {
  60.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+16,y[i]+16,rt[i]);    
  61.                 x[i] = x[i] + sp[i];
  62.                 if (x[i]>640)                                            
  63.                 {
  64.                     x[i] = -64;
  65.                     y[i] = GetRandom(0,480)-48;
  66.                 }
  67.             }
  68.         }
  69.  
  70.         if (total_step>=128 && total_step<256)                                
  71.         {
  72.             for (i=0;i!=24;i++)
  73.             {
  74.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],320,240,r);            
  75.             }
  76.             r+=8;                                                    
  77.         }
  78.  
  79.         if (total_step>=256 && total_step<384)                                
  80.         {
  81.             for (i=0;i!=24;i++)
  82.             {
  83.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],300,250,r);            
  84.                 x[i] = x[i] + sp[i];
  85.                 if (x[i]>640)                                            
  86.                 {
  87.                     x[i] = -64;
  88.                     y[i] = GetRandom(0,480)-48;
  89.                 }
  90.     
  91.             }
  92.             r-=8;
  93.         }
  94.  
  95.         if (total_step>=384 && total_step<511)                                
  96.         {
  97.             for (i=0;i!=24;i++)
  98.             {
  99.                 rt[i] = x[i]*4;
  100.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+16,y[i]+16,rt[i]);    
  101.                 x[i] = x[i] + sp[i];
  102.                 if (x[i]>640)
  103.                 {
  104.                     x[i] = -64;
  105.                     y[i] = GetRandom(0,480)-48;
  106.                 }
  107.             }
  108.         }
  109.  
  110.         if (total_step == 511)                                            
  111.         {
  112.             total_step =0;
  113.             r = 0;
  114.         }
  115.         
  116.         N_Cel_Loop2(0,0);                                                
  117.         total_step++;
  118.     }
  119.     while (!Button());
  120.  
  121.     ShowMenuBar();
  122.     ShowCursor();
  123.     FlushEvents( everyEvent, 0 ); 
  124.     ColorRevert();
  125. }
  126.  
  127.  
  128.  
  129.